//
//  WBMainViewController.swift
//  ddWeibo
//
//  Created by 晓东 on 2017/11/1.
//  Copyright © 2017年 晓东. All rights reserved.
//

import UIKit

class WBMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
//        tabBar.backgroundImage = UIImage.init(named: "tabbar_background")
        
        setupChildViewController()
        
    }

}


extension WBMainViewController{
    
    private func setupChildViewController(){
        let array = [
            ["clsName":"WBHomeViewController", "title":"首页","imageName":"home"]
        ]
        
        for dic in array {
            addChildViewController(controller(dict: dic))
        }
    }
    
    private func controller(dict: [String: String]) -> UIViewController{
        
       guard let clsName  = dict["clsName"],
           let  title = dict["title"],
           let  imageName = dict["imageName"],
           let  cls = NSClassFromString(Bundle.main.nameSpace + "." + clsName) as? UIViewController.Type
            else {
                return UIViewController()
            }
        let vc = cls.init()
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage.init(named: "tabbar_" + imageName)
        vc.tabBarItem.selectedImage = UIImage.init(named: "tabbar_" + imageName + "_highlighted")
        
        let nav = WBNavigationController.init(rootViewController: vc)
        
        return nav
    }
    
}
